package com.lzm.ydpt.module.mall.activity;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.byt.framlib.base.BaseActivity;
import com.byt.framlib.baseadapter.rv.RvCommonAdapter;
import com.byt.framlib.baseadapter.rv.RvViewHolder;
import com.byt.framlib.commonwidget.LoadingTip;
import com.byt.framlib.commonwidget.NormalTitleBar;
import com.byt.framlib.commonwidget.OnNoDoubleClickListener;
import com.byt.framlib.commonwidget.refresh.RefreshHeaderView;
import com.lzm.ydpt.R;
import com.lzm.ydpt.entity.mall.ProductBean;
import com.lzm.ydpt.module.mall.utils.ProductUtil;
import com.lzm.ydpt.mvp.contract.ProductLoveContract;
import com.lzm.ydpt.mvp.presenterimpl.ProductLovePresenterImpl;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 店铺收藏
 */
public class ProductLoveActivity extends BaseActivity<ProductLovePresenterImpl> implements ProductLoveContract.View {
    @BindView(R.id.ntb_product_love)
    NormalTitleBar ntb_product_love;
    @BindView(R.id.ltp_product_love)
    LoadingTip ltp_product_love;
    @BindView(R.id.srf_product_love)
    SmartRefreshLayout srf_product_love;
    @BindView(R.id.rv_product_love)
    RecyclerView rv_product_love;
    private RvCommonAdapter<ProductBean> commonAdapter = null;
    private List<ProductBean> sproBeans = new ArrayList<>();
    @Override
    public int getLayoutId() {
        return R.layout.activity_product_love;
    }

    @Override
    public ProductLovePresenterImpl initPreData() {
        return new ProductLovePresenterImpl(this);
    }

    @Override
    public void initView() {
        setNtbTitle(ntb_product_love, true);
        ntb_product_love.setTitleText("收藏夹");
        ntb_product_love.setOnBackListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                finish();
            }
        });
        initRefrsh();
        initAdapter();

    }

    private void initRefrsh() {
        setRefreshLayout(srf_product_love);
        srf_product_love.setEnableRefresh(true);
        srf_product_love.setEnableLoadMore(false);
        srf_product_love.setRefreshHeader(new RefreshHeaderView(mBContext).getHeaderStyleStaffF4());
        srf_product_love.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {

            }
        });
    }

    private void initAdapter() {
        rv_product_love.setLayoutManager(new LinearLayoutManager(mBContext));
        commonAdapter = new RvCommonAdapter<ProductBean>(mBContext, sproBeans, R.layout.item_product_common_rv) {
            @Override
            protected void convert(RvViewHolder holder, ProductBean shopInfoBean, int position) {
                ProductUtil.initRVProductData(holder,position,shopInfoBean);
                holder.setOnClickListener(R.id.tv_show_look_same, new OnNoDoubleClickListener() {
                    @Override
                    protected void onNoDoubleClick(View v) {

                    }
                });
                holder.setOnClickListener(R.id.tv_show_add_cart, new OnNoDoubleClickListener() {
                    @Override
                    protected void onNoDoubleClick(View v) {

                    }
                });
            }
        };
        rv_product_love.setAdapter(commonAdapter);
    }


    @Override
    public void showMessage(String message, String method) {

    }

    @Override
    public void showErrorView(String msg) {

    }

    @Override
    public void onProductLove(List<ProductBean> list) {

    }
}
